package com.yanshaohui.controller;

import com.yanshaohui.bean.Person;
import com.yanshaohui.configuations.reactiveRedis.PersonRedisTemplate;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * Created by TS-Ysh on 2018-05-14.
 */
@RestController
public class ReactRedisController {

//    @Autowired
//    private ReactiveRedisTemplate<String, Person> redisTemplate;

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    private PersonRedisTemplate personRedisTemplate;

//    @Autowired
//    private ReactiveRedisTemplate<String, Object> redisTemplate2;

    @RequestMapping("/redis/save/person/{id}/{name}")
    public Mono<Void> savePerson(@PathVariable("id") Long id,@PathVariable("name") String name){
        return personRedisTemplate.opsForValue().set(id.toString(),new Person(id,name,1,"地球",99)).then();
    }

    @RequestMapping("/redis/get/person/{id}")
    public Mono<Person> getPerson(@PathVariable("id") Long id){
        return personRedisTemplate.opsForValue().get(id.toString());
    }

//    @RequestMapping("/redis/save/person/{id}/{name}")
//    public Mono<Boolean> savePerson2(@PathVariable("id") Long id,@PathVariable("name") String name){
//        return redisTemplate2.opsForValue().setIfAbsent(id.toString(),new Person(id,name,1,"地球",99));
//    }
//
//    @RequestMapping("/redis/get/person/{id}")
//    public Mono<Object> getPerson2(@PathVariable("id") Long id){
//        return redisTemplate2.opsForValue().get(id.toString());
//    }
}
